﻿@{
    ViewBag.Title = string.Format("{0}", GetString("PowerName"));
    Layout = "~/Views/Shared/_ListLayout.cshtml";
}
@inherits CMSWebViewPage<object>
@section Head{
    @Html.CreateDialogSource()
}
<div id="toolbar_powerinfo" class="datagrid-toolbar">
    @CurrentButtonTool.Create()
    <div>
        <form id="fr_search_powerinfo">
            @Html.QueryComboBox("权限类型", "PowerType", new List<SelectListItem>
            {
                new SelectListItem{Value="0",Text="分类"},
                new SelectListItem{Value="1",Text="功能"},
                new SelectListItem{Value="2",Text="按钮"}
            })
            @Html.QueryComboBox("位置", "Position", new List<SelectListItem>
            {
                new SelectListItem{Value="0",Text="无"},
                new SelectListItem{Value="1",Text="顶部工具栏"},
                new SelectListItem{Value="2",Text="右键工具栏"},
                new SelectListItem{Value="3",Text="普通工具栏"}
            })
            <a href="javascript:void(0)" onclick="Search();" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">Search</a>
        </form>
    </div>
</div>
<table id="dg_powerinfo" data-options="url:'/powerinfo/listjson?parentid=@TransferID',border:false,fit:true,fitColumns:true,toolbar:'#toolbar_powerinfo',singleSelect:true,pagination:true,pageSize:20">
    <thead>
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            <th data-options="field:'Id',width:20,align:'center'">ID</th>
            <th data-options="field:'PowerName',width:30,align:'center'">名称</th>
            <th data-options="field:'AreaName',width:20,align:'center'">区域</th>
            <th data-options="field:'ControllerName',width:35,align:'center'">控制器</th>
            <th data-options="field:'ActionName',width:35,align:'center'">Action</th>
            <th data-options="field:'LinkUrl',width:60,align:'center'">链接地址</th>
            <th data-options="field:'Execution',width:30,align:'center'">执行脚本</th>
            @*<th data-options="field:'HasChild',formatter:BooleanToString,width:30,align:'center'">是否有子节点</th>*@
            <th data-options="field:'PowerType',formatter:FormatPowerType,width:20,align:'center'">权限类型</th>
            <th data-options="field:'Position',formatter:FomentPosition,width:30,align:'center'">位置</th>
            @*<th data-options="field:'Icon',formatter:PreviewIcon,width:20,align:'center'">图标</th>*@
            <th data-options="field:'IsDisplay',formatter:BooleanToString,width:20,align:'center'">是否显示</th>
            @*<th data-options="field:'SortIndex',width:20,align:'center'">排序号</th>*@
            <th data-options="field:'CreateDate',formatter:JsonToDate,width:40,align:'center'">创建时间</th>
        </tr>
    </thead>
</table>
<div id="dialog_powersort" class="easyui-dialog" title="权限排序" data-options="iconCls:'icon-save',closed:true,width:350,height:400">
</div>
@section Bottom{
    <script type="text/javascript">
        var objBizDatagrid = new BizDatagrid('#dg_powerinfo');
        function Add() {
            objBizDatagrid.add("/powerinfo/editpage?ParentName=@(GetString("PowerName"))");
        }
        function Move() {
            var objRow = objBizDatagrid.selectRow();
            if (objRow) {
                TransferToUrl("/PowerInfo/MovePowers?powerId=" + objRow.Id + "&ParentName=@(GetString("PowerName"))&PowerName=" + objRow.PowerName);
            } else {
                ShowMessage("请选择一项");
            }
        }
        function Copy() {
            var objRow = objBizDatagrid.selectRow();
            if (objRow) {
                TransferToUrl("/PowerInfo/CopyPower?powerId=" + objRow.Id + "&ParentName=@(GetString("PowerName"))&PowerName=" + objRow.PowerName);
            } else {
                ShowMessage("请选择一项");
            }
        }
        function SyncRedis() {
            var objAjaxEntity = new AjaxEntity();
            objAjaxEntity.url = "/PowerInfo/SyncRedis";
            objAjaxEntity.executing = function () {
                ShowProcess();
                return true;
            };
            objAjaxEntity.executeSuccess = function (invokeresult) {
                ShowMessage(invokeresult.ResultMessage);
                CloseProcess();
            };
            objAjaxEntity.execute();
        }
        function QuickAdd() {
            var objRow = objBizDatagrid.selectRow();
            if (objRow) {
                TransferToUrl("/powerinfo/quickadd?powerId=" + objRow.Id + "&ParentName=@(GetString("PowerName"))&PowerName=" + objRow.PowerName);
        } else {
            ShowMessage("请选择一项");
        }
    }
    function Edit() {
        objBizDatagrid.edit("/powerinfo/editpage?ParentName=@(GetString("PowerName"))");
        }
        function Search() {
            objBizDatagrid.search('#fr_search_powerinfo', '/powerinfo/listjson?parentid=@TransferID');
        }
        function Delete() {
            objBizDatagrid.del('/powerinfo/delete/', "Id", function () {
                var $tree = window.parent.objBizTree.source;
                $tree.tree({
                    onLoadSuccess: function () {
                        var node = $tree.tree('find', "@TransferID");
                        $tree.tree('expandTo', node.target);
                        $tree.tree('select', node.target);
                    }
                });
            });
        }
        function FormatPowerType(val) {
            switch (val) {
                case 0:
                    return "分类";
                case 1:
                    return "功能";
                case 2:
                    return "按钮";
                default:
                    return "未知";
            }
        }
        function FomentPosition(val) {
            switch (val) {
                case 0:
                    return "无";
                case 1:
                    return "顶部工具栏";
                case 2:
                    return "右键工具栏";
                case 3:
                    return "普通工具栏";
                default:
                    return "未知";
            }
        }
        function PreviewIcon(val, row) {
            return '<span class="l-btn-left l-btn-icon-left"><span class="l-btn-text"></span><span class="l-btn-icon ' + row.Icon + '"></span></span>';
        }
        function Sort() {
            var objBizDialog = new BizDialog("#dialog_powersort",
            {
                href: "/PowerInfo/SortPowers?parentId=@TransferID&dialog=dialog_powersort",
                onClose: function () {
                    var invokeResult = GetItem("dialog_powersort");
                    if (invokeResult) {
                        if (invokeResult.ResultCode == "Success") {
                            objBizDatagrid.reload();
                            var $tree = window.parent.objBizTree.source;
                            $tree.tree({
                                onLoadSuccess: function () {
                                    var node = $tree.tree('find', "@TransferID");
                                    $tree.tree('expandTo', node.target);
                                    $tree.tree('select', node.target);
                                }
                            });
                        }
                        ShowMessage(invokeResult.ResultMessage);
                        DeleteItem("dialog_powersort");
                    }
                }
            });
            objBizDialog.open();
        }
    </script>
}
